import final from './final';
import promi from './promiseTimeout';
import Deferred from './Deferred';
export const promiseQueue=({
    timeout=5
}={})=>{
    let done=0;
    const queue=[];

    const deferred=Deferred();

    const add=(fn)=>{
        if(checkDone()){
            throw('queue已经执行完毕');
        }
        queue.push(Promise.resolve(fn()));

    };
    const checkDone=()=>{
        if(done>=queue.length){
            return true;
        }
    };
    return deferred;
    const _addPool=(fn)=>{
        let _id=id++;
        doPools.push(_id);
        final(fn(),()=>{
            const index=doPools.indexOf(_id);
            if(index<-1){
                return;
            }
            doPools.splice(index,1);
            runWillPool();
        });
        return _id;
    };
    const runWillPool=()=>{
        if(doPools.length>=size){
            return;
        }
        const fn=willPools.shift();
        if(!fn){
            return;
        }
        addPool(fn);
    };

    return {

    };
};
export default promiseQueue;